
********************************************************************************
**********Conduct BOTE (Figure 8,Figure 9,Table 2)******************************
********************************************************************************	
* set path

	clear all
	global path "~/agriculture_temperature"
	
	global temp "~/revision_codes/temp"
	global visual "~/revision_codes/visual"
	
	use $path/data/merged_for_reg, clear
	
* bote based on value regressions -- baseline SR estimates

	xtset ctycode year	
	
	foreach r in 1 2 {
	foreach y in farming forest livestock fishery {
	foreach x in 05 10 15 20 {
	foreach t in Neg 0 5 10 15 20 25 30 35 {
		qui sum DF`x'_dd5bin`t' if inrange(year,1995,2015) & region3==`r' [aweight=`y'_output]
		global df`x'_b`t'_`r'_`y' = r(mean)
		}
	}
	}
	}
	
	* drop ref bin
	drop dd5bin10
	
	foreach r in 1 2 {
		foreach y in farming forest livestock fishery {
			qui reghdfe ln_`y'_output dd5bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & region3==`r', ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store region`r'_`y'_5C
			}
		}	
		
	
	foreach r in 1 2 {
	foreach y in farming forest livestock fishery {
	foreach x in 05 10 15 20 {
		estimates restore region`r'_`y'_5C
		
		di `x' "*0.1 degrees " "`y'" " region" `r'
		lincomest dd5bin0*${df`x'_b0_`r'_`y'}+dd5bin5*${df`x'_b5_`r'_`y'}+ ///
			   dd5binNeg*${df`x'_bNeg_`r'_`y'}+dd5bin15*${df`x'_b15_`r'_`y'}+ ///
			   dd5bin20*${df`x'_b20_`r'_`y'}+dd5bin25*${df`x'_b25_`r'_`y'}+ ///
			   dd5bin30*${df`x'_b30_`r'_`y'}+dd5bin35*${df`x'_b35_`r'_`y'}
        parmest,label saving($temp/sr_`y'_`r'_`x'.dta,replace) idnum(`x') idstr("`y'")				   
			   }
			   }
			}
		
		
* bote based on LD est	
* set path

	clear all
	

	global path "~/agriculture_temperature"
	
	global temp "~/revision_codes/temp"
	global visual "~/revision_codes/visual"
	
	use $path/data/merged_for_reg, clear	
	xtset ctycode year	

	foreach x in aoutput farming_output forest_output livestock_output fishery_output{
		rangestat (mean) ld_`x' = `x', interval(year -4,0) by(ctycode)
		}

	foreach x in dd5bin0 dd5bin5 dd5binNeg dd5bin15 dd5bin20 dd5bin25 dd5bin30 dd5bin35 pre ssd rhu prs win {
		rangestat (mean) ld_`x' = `x', interval(year -4,0) by(ctycode)
		}			

	foreach x in aoutput farming_output forest_output livestock_output fishery_output{
		gen ln_ld_`x' = log(ld_`x')
		}			
			
	foreach r in 1 2 {
		foreach y in farming forest livestock fishery {
			qui reghdfe ln_ld_`y'_output ld_dd5bin* ///
					c.ld_pre##c.ld_pre c.ld_ssd##c.ld_ssd c.ld_rhu##c.ld_rhu c.ld_prs##c.ld_prs c.ld_win##c.ld_win ///
					i.pro#c.year##c.year ///
					if inlist(year,2000,2005,2010,2015) & region3==`r', ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store region`r'_`y'_LD5C
			}
		}	
		

	foreach r in 1 2 {
	foreach y in farming forest livestock fishery {
	foreach x in 05 10 15 20 {
		estimates restore region`r'_`y'_LD5C
		
		di `x' "*0.1 degrees " "`y'" " region" `r'
		lincomest ld_dd5bin0*${df`x'_b0_`r'_`y'}+ld_dd5bin5*${df`x'_b5_`r'_`y'}+ ///
			   ld_dd5binNeg*${df`x'_bNeg_`r'_`y'}+ld_dd5bin15*${df`x'_b15_`r'_`y'}+ ///
			   ld_dd5bin20*${df`x'_b20_`r'_`y'}+ld_dd5bin25*${df`x'_b25_`r'_`y'}+ ///
			   ld_dd5bin30*${df`x'_b30_`r'_`y'}+ld_dd5bin35*${df`x'_b35_`r'_`y'}
        parmest,label saving($temp/ld_`y'_`r'_`x'.dta,replace) idnum(`x') idstr("`y'")				   
			   }
			   }
			}			

	
* distributed-lag version on values

	
	use $path/data/merged_for_reg, clear		
	xtset ctycode year	

		foreach r in 1 2 {
		foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
		foreach t in Neg 0 5 10 15 20 25 30 35 {
			sum DF`x'_dd5bin`t' if inrange(year,1995,2015) & region3==`r' [aweight=`y'_output]
			global df`x'_b`t'_`r'_`y' = r(mean)			
			forvalues s = 1/5{ 
				sum L`s'DF`x'_dd5bin`t' if inrange(year,1995,2015) & region3==`r' [aweight=`y'_output]
				global L`s'df`x'_b`t'_`r'_`y' = r(mean)	
				}
			}
		}
		}	
		}
		
		* drop ref bin
		drop *dd5bin10*
		
		foreach r in 1 2 {
		foreach x in farming livestock forest fishery {
				qui reghdfe ln_`x'_output dd5bin* L?dd5bin* ///
				c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
				L?pre* L?ssd* L?rhu* L?prs* L?win* ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & region3==`r', ///
					absorb(ctycode year) cluster(ctycode proXyear) 
				estimates store `x'_dl5_`r'			
				}
		}
	
	foreach r in 1 2 {
	foreach y in farming forest livestock fishery {
	foreach x in 05 10 15 20 {
		estimates restore `y'_dl5_`r'	
		di `x' "*0.1 degrees " "`y'" " region" `r'
		lincomest dd5bin0*${df`x'_b0_`r'_`y'}+dd5bin5*${df`x'_b5_`r'_`y'}+ ///
			   dd5binNeg*${df`x'_bNeg_`r'_`y'}+dd5bin15*${df`x'_b15_`r'_`y'}+ ///
			   dd5bin20*${df`x'_b20_`r'_`y'}+dd5bin25*${df`x'_b25_`r'_`y'}+ ///
			   dd5bin30*${df`x'_b30_`r'_`y'}+dd5bin35*${df`x'_b35_`r'_`y'}
        parmest,label saving($temp/dl_sr_`y'_`r'_`x'.dta,replace) idnum(`x') idstr("`y'")	
				
		estimates restore `y'_dl5_`r'	
		di `x' "*0.1 degrees " "`y'" " region" `r'
		lincomest L1dd5bin0*${L1df`x'_b0_`r'_`y'}+L1dd5bin5*${L1df`x'_b5_`r'_`y'}+ ///
			   L1dd5binNeg*${L1df`x'_bNeg_`r'_`y'}+L1dd5bin15*${L1df`x'_b15_`r'_`y'}+ ///
			   L1dd5bin20*${L1df`x'_b20_`r'_`y'}+L1dd5bin25*${L1df`x'_b25_`r'_`y'}+ ///
			   L1dd5bin30*${L1df`x'_b30_`r'_`y'}+L1dd5bin35*${L1df`x'_b35_`r'_`y'}+ ///
			   L2dd5bin0*${L2df`x'_b0_`r'_`y'}+L2dd5bin5*${L2df`x'_b5_`r'_`y'}+ ///
			   L2dd5binNeg*${L2df`x'_bNeg_`r'_`y'}+L2dd5bin15*${L2df`x'_b15_`r'_`y'}+ ///
			   L2dd5bin20*${L2df`x'_b20_`r'_`y'}+L2dd5bin25*${L2df`x'_b25_`r'_`y'}+ ///
			   L2dd5bin30*${L2df`x'_b30_`r'_`y'}+L2dd5bin35*${L2df`x'_b35_`r'_`y'}+ ///
 			   L3dd5bin0*${L3df`x'_b0_`r'_`y'}+L3dd5bin5*${L3df`x'_b5_`r'_`y'}+ ///
			   L3dd5binNeg*${L3df`x'_bNeg_`r'_`y'}+L3dd5bin15*${L3df`x'_b15_`r'_`y'}+ ///
			   L3dd5bin20*${L3df`x'_b20_`r'_`y'}+L3dd5bin25*${L3df`x'_b25_`r'_`y'}+ ///
			   L3dd5bin30*${L3df`x'_b30_`r'_`y'}+L3dd5bin35*${L3df`x'_b35_`r'_`y'}+ ///
 			   L4dd5bin0*${L4df`x'_b0_`r'_`y'}+L4dd5bin5*${L4df`x'_b5_`r'_`y'}+ ///
			   L4dd5binNeg*${L4df`x'_bNeg_`r'_`y'}+L4dd5bin15*${L4df`x'_b15_`r'_`y'}+ ///
			   L4dd5bin20*${L4df`x'_b20_`r'_`y'}+L4dd5bin25*${L4df`x'_b25_`r'_`y'}+ ///
			   L4dd5bin30*${L4df`x'_b30_`r'_`y'}+L4dd5bin35*${L4df`x'_b35_`r'_`y'}+ ///
			   L5dd5bin0*${L5df`x'_b0_`r'_`y'}+L5dd5bin5*${L5df`x'_b5_`r'_`y'}+ ///
			   L5dd5binNeg*${L5df`x'_bNeg_`r'_`y'}+L5dd5bin15*${L5df`x'_b15_`r'_`y'}+ ///
			   L5dd5bin20*${L5df`x'_b20_`r'_`y'}+L5dd5bin25*${L5df`x'_b25_`r'_`y'}+ ///
			   L5dd5bin30*${L5df`x'_b30_`r'_`y'}+L5dd5bin35*${L5df`x'_b35_`r'_`y'}		   
        parmest,label saving($temp/dl_ir_`y'_`r'_`x'.dta,replace) idnum(`x') idstr("`y'")	
			   }
			   }
			}		
		
			
		
* MA version on values

	
	use $path/data/merged_for_reg, clear		
	xtset ctycode year	

	* northern
		
		foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
		foreach t in Neg 0 5 10 15 20 25 30 35 {
			 sum DF`x'_dd5bin`t' if inrange(year,1995,2015) & region3==1 [aweight=`y'_output]
			global df`x'_b`t'_`y' = r(mean)			
			 sum ma5DF`x'_dd5bin`t' if inrange(year,1995,2015) & region3==1 [aweight=`y'_output]
			global ma5df`x'_b`t'_`y' = r(mean)			
			}
		}
		}
	
	
		foreach y in farming forest livestock fishery {
				qui reghdfe ln_`y'_output dd5bin0 dd5bin5 dd5binNeg dd5bin15 dd5bin20 dd5bin25 dd5bin30 dd5bin35 ///
				c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					ma5dd5bin0 ma5dd5bin5 ma5dd5binNeg ma5dd5bin15 ma5dd5bin20 ma5dd5bin25 ma5dd5bin30 ma5dd5bin35 ///
					c.ma5pre##c.ma5pre c.ma5ssd##c.ma5ssd c.ma5rhu##c.ma5rhu c.ma5prs##c.ma5prs c.ma5win##c.ma5win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & region3==1, ///
					absorb(ctycode year) cluster(ctycode proXyear) 
				estimates store n_`y'_output_ma5
				}
				
		esttab n_*output*ma5, b(4) se(4) keep(*dd*)	brackets star(* 0.1 ** 0.05 *** 0.01) r2(4)
		
		foreach x in 05 10 15 20 {	
		foreach y in farming forest livestock fishery {
		estimates restore n_`y'_output_ma5
		
		di `x' "*0.1 degrees " "`y'" " output (current)"		
		lincomest dd5bin0*${df`x'_b0_`y'}  +dd5bin5*${df`x'_b5_`y'}  +dd5binNeg*${df`x'_bNeg_`y'}+ ///
			   dd5bin15*${df`x'_b15_`y'}+dd5bin20*${df`x'_b20_`y'}+dd5bin25*${df`x'_b25_`y'}+ ///
			   dd5bin30*${df`x'_b30_`y'}+dd5bin35*${df`x'_b35_`y'}
        parmest,label saving($temp/ma_sr_`y'_1_`x'.dta,replace) idnum(`x') idstr("`y'")				   
			   
		estimates restore n_`y'_output_ma5
		di `x' "*0.1 degrees " "`y'" " output (MA)"		
		lincomest ma5dd5bin0*${ma5df`x'_b0_`y'}  +ma5dd5bin5*${ma5df`x'_b5_`y'}  +ma5dd5binNeg*${ma5df`x'_bNeg_`y'}+ ///
			   ma5dd5bin15*${ma5df`x'_b15_`y'}+ma5dd5bin20*${ma5df`x'_b20_`y'}+ma5dd5bin25*${ma5df`x'_b25_`y'}+ ///
			   ma5dd5bin30*${ma5df`x'_b30_`y'}+ma5dd5bin35*${ma5df`x'_b35_`y'}			   			   
        parmest,label saving($temp/ma_ir_`y'_1_`x'.dta,replace) idnum(`x') idstr("`y'")				   
			   }
			   }		
****Table 2
		* combined SR + IR
				foreach x in 05 10 15 20 {	
		foreach y in farming forest livestock fishery {
		estimates restore n_`y'_output_ma5
		
		di `x' "*0.1 degrees " "`y'" " output overall"		
		lincom dd5bin0*${df`x'_b0_`y'}  +dd5bin5*${df`x'_b5_`y'}  +dd5binNeg*${df`x'_bNeg_`y'}+ ///
			   dd5bin15*${df`x'_b15_`y'}+dd5bin20*${df`x'_b20_`y'}+dd5bin25*${df`x'_b25_`y'}+ ///
			   dd5bin30*${df`x'_b30_`y'}+dd5bin35*${df`x'_b35_`y'} + ///
			   ma5dd5bin0*${ma5df`x'_b0_`y'}  +ma5dd5bin5*${ma5df`x'_b5_`y'}  +ma5dd5binNeg*${ma5df`x'_bNeg_`y'}+ ///
			   ma5dd5bin15*${ma5df`x'_b15_`y'}+ma5dd5bin20*${ma5df`x'_b20_`y'}+ma5dd5bin25*${ma5df`x'_b25_`y'}+ ///
			   ma5dd5bin30*${ma5df`x'_b30_`y'}+ma5dd5bin35*${ma5df`x'_b35_`y'}				   			   
			   }
			   }	
			   
		* test SR vs IR
				foreach x in 05 10 15 20 {	
		foreach y in farming forest livestock fishery {
		estimates restore n_`y'_output_ma5
		
		di `x' "*0.1 degrees " "`y'" " output overall"		
		lincom dd5bin0*${df`x'_b0_`y'}  +dd5bin5*${df`x'_b5_`y'}  +dd5binNeg*${df`x'_bNeg_`y'}+ ///
			   dd5bin15*${df`x'_b15_`y'}+dd5bin20*${df`x'_b20_`y'}+dd5bin25*${df`x'_b25_`y'}+ ///
			   dd5bin30*${df`x'_b30_`y'}+dd5bin35*${df`x'_b35_`y'} - ///
			   (ma5dd5bin0*${ma5df`x'_b0_`y'}  +ma5dd5bin5*${ma5df`x'_b5_`y'}  +ma5dd5binNeg*${ma5df`x'_bNeg_`y'}+ ///
			   ma5dd5bin15*${ma5df`x'_b15_`y'}+ma5dd5bin20*${ma5df`x'_b20_`y'}+ma5dd5bin25*${ma5df`x'_b25_`y'}+ ///
			   ma5dd5bin30*${ma5df`x'_b30_`y'}+ma5dd5bin35*${ma5df`x'_b35_`y'})				   			   
			   }
			   }				   
		
		
	* southern bote
	
		foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
		foreach t in Neg 0 5 10 15 20 25 30 35 {
			 sum DF`x'_dd5bin`t' if inrange(year,1995,2015) & region3==2 [aweight=`y'_output]
			global df`x'_b`t'_`y' = r(mean)			
			 sum ma5DF`x'_dd5bin`t' if inrange(year,1995,2015) & region3==2 [aweight=`y'_output]
			global ma5df`x'_b`t'_`y' = r(mean)			
			}
		}
		}
	
	
		foreach y in farming forest livestock fishery {
				qui reghdfe ln_`y'_output dd5bin0 dd5bin5 dd5binNeg dd5bin15 dd5bin20 dd5bin25 dd5bin30 dd5bin35 ///
				c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					ma5dd5bin0 ma5dd5bin5 ma5dd5binNeg ma5dd5bin15 ma5dd5bin20 ma5dd5bin25 ma5dd5bin30 ma5dd5bin35 ///
					c.ma5pre##c.ma5pre c.ma5ssd##c.ma5ssd c.ma5rhu##c.ma5rhu c.ma5prs##c.ma5prs c.ma5win##c.ma5win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & region3==2, ///
					absorb(ctycode year) cluster(ctycode proXyear) 
				estimates store s_`y'_output_ma5
				}
				
		esttab s_*output*ma5, b(4) se(4) keep(*dd*)	brackets star(* 0.1 ** 0.05 *** 0.01) r2(4)
			
		foreach x in 05 10 15 20 {	
		foreach y in farming forest livestock fishery {
		estimates restore s_`y'_output_ma5
		
		di `x' "*0.1 degrees " "`y'" " output (current)"		
		lincomest dd5bin0*${df`x'_b0_`y'}  +dd5bin5*${df`x'_b5_`y'}  +dd5binNeg*${df`x'_bNeg_`y'}+ ///
			   dd5bin15*${df`x'_b15_`y'}+dd5bin20*${df`x'_b20_`y'}+dd5bin25*${df`x'_b25_`y'}+ ///
			   dd5bin30*${df`x'_b30_`y'}+dd5bin35*${df`x'_b35_`y'}
        parmest,label saving($temp/ma_sr_`y'_2_`x'.dta,replace) idnum(`x') idstr("`y'")				   
			   
		estimates restore s_`y'_output_ma5
		di `x' "*0.1 degrees " "`y'" " output (MA)"		
		lincomest ma5dd5bin0*${ma5df`x'_b0_`y'}  +ma5dd5bin5*${ma5df`x'_b5_`y'}  +ma5dd5binNeg*${ma5df`x'_bNeg_`y'}+ ///
			   ma5dd5bin15*${ma5df`x'_b15_`y'}+ma5dd5bin20*${ma5df`x'_b20_`y'}+ma5dd5bin25*${ma5df`x'_b25_`y'}+ ///
			   ma5dd5bin30*${ma5df`x'_b30_`y'}+ma5dd5bin35*${ma5df`x'_b35_`y'}			   			   
        parmest,label saving($temp/ma_ir_`y'_2_`x'.dta,replace) idnum(`x') idstr("`y'")				   
			   }
			   }		

		* combined SR + IR
				foreach x in 05 10 15 20 {	
		foreach y in farming forest livestock fishery {
		estimates restore s_`y'_output_ma5
		
		di `x' "*0.1 degrees " "`y'" " output overall"		
		lincom dd5bin0*${df`x'_b0_`y'}  +dd5bin5*${df`x'_b5_`y'}  +dd5binNeg*${df`x'_bNeg_`y'}+ ///
			   dd5bin15*${df`x'_b15_`y'}+dd5bin20*${df`x'_b20_`y'}+dd5bin25*${df`x'_b25_`y'}+ ///
			   dd5bin30*${df`x'_b30_`y'}+dd5bin35*${df`x'_b35_`y'} + ///
			   ma5dd5bin0*${ma5df`x'_b0_`y'}  +ma5dd5bin5*${ma5df`x'_b5_`y'}  +ma5dd5binNeg*${ma5df`x'_bNeg_`y'}+ ///
			   ma5dd5bin15*${ma5df`x'_b15_`y'}+ma5dd5bin20*${ma5df`x'_b20_`y'}+ma5dd5bin25*${ma5df`x'_b25_`y'}+ ///
			   ma5dd5bin30*${ma5df`x'_b30_`y'}+ma5dd5bin35*${ma5df`x'_b35_`y'}				   			   
			   }
			   }	
			   
		* test SR vs IR
				foreach x in 05 10 15 20 {	
		foreach y in farming forest livestock fishery {
		estimates restore s_`y'_output_ma5
		
		di `x' "*0.1 degrees " "`y'" " output overall"		
		lincom dd5bin0*${df`x'_b0_`y'}  +dd5bin5*${df`x'_b5_`y'}  +dd5binNeg*${df`x'_bNeg_`y'}+ ///
			   dd5bin15*${df`x'_b15_`y'}+dd5bin20*${df`x'_b20_`y'}+dd5bin25*${df`x'_b25_`y'}+ ///
			   dd5bin30*${df`x'_b30_`y'}+dd5bin35*${df`x'_b35_`y'} - ///
			   (ma5dd5bin0*${ma5df`x'_b0_`y'}  +ma5dd5bin5*${ma5df`x'_b5_`y'}  +ma5dd5binNeg*${ma5df`x'_bNeg_`y'}+ ///
			   ma5dd5bin15*${ma5df`x'_b15_`y'}+ma5dd5bin20*${ma5df`x'_b20_`y'}+ma5dd5bin25*${ma5df`x'_b25_`y'}+ ///
			   ma5dd5bin30*${ma5df`x'_b30_`y'}+ma5dd5bin35*${ma5df`x'_b35_`y'})				   			   
			   }
			   }				   
	
********************************************************************************
**** Arrange results for visualization
********************************************************************************

* Baseline estimates SR BOTE 

		clear	
		foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
				append using $temp/sr_`y'_1_`x'.dta	
				}
				}
			gen region = "North"
			
		foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
				append using $temp/sr_`y'_2_`x'.dta	
				}
				}		
			replace region = "South" if region == ""			
		
		drop label
		rename idnum level
		rename estimate coef 
		rename stderr se 
		rename min95 ci_l
		rename max95 ci_h	
		rename idstr sector
		replace sector = "Cropping" if sector=="farming"
		replace sector = "Forestry" if sector=="forest"
		replace sector = "Livestock" if sector=="livestock"
		replace sector = "Fishery" if sector=="fishery"
		
		save $visual/bote_sr_base, replace	
	
* LD estimates IR BOTE 

		clear	
		foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
				append using $temp/ld_`y'_1_`x'.dta	
				}
				}
			gen region = "North"
			
		foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
				append using $temp/ld_`y'_2_`x'.dta	
				}
				}		
			replace region = "South" if region == ""			
		
		drop label
		rename idnum level
		rename estimate coef 
		rename stderr se 
		rename min95 ci_l
		rename max95 ci_h	
		rename idstr sector
		replace sector = "Cropping" if sector=="farming"
		replace sector = "Forestry" if sector=="forest"
		replace sector = "Livestock" if sector=="livestock"
		replace sector = "Fishery" if sector=="fishery"
		
		save $visual/bote_ld_base, replace		
		
* combine SR & LD results

		use $visual/bote_sr_base, clear
		gen type = "baseline"
		append using $visual/bote_ld_base
		replace type = "long-diff" if type==""
		
		save $visual/bote_sr_ld, replace

* MA estimates

		clear	
		foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
				append using $temp/ma_sr_`y'_1_`x'.dta	
				}
				}
			gen region = "North"
			
		foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
				append using $temp/ma_sr_`y'_2_`x'.dta	
				}
				}		
			replace region = "South" if region == ""	
			
			gen type = "short-run"

			foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
				append using $temp/ma_ir_`y'_1_`x'.dta	
				}
				}
			replace region = "North" if region == ""
			
		foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
				append using $temp/ma_ir_`y'_2_`x'.dta	
				}
				}		
			replace region = "South" if region == ""					
			
			replace type = "intermediate-run" if type == ""
		
		drop label
		rename idnum level
		rename estimate coef 
		rename stderr se 
		rename min95 ci_l
		rename max95 ci_h	
		rename idstr sector
		replace sector = "Cropping" if sector=="farming"
		replace sector = "Forestry" if sector=="forest"
		replace sector = "Livestock" if sector=="livestock"
		replace sector = "Fishery" if sector=="fishery"
		
		save $visual/bote_ma, replace				
		
* DL estimates

		clear	
		foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
				append using $temp/dl_sr_`y'_1_`x'.dta	
				}
				}
			gen region = "North"
			
		foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
				append using $temp/dl_sr_`y'_2_`x'.dta	
				}
				}		
			replace region = "South" if region == ""	
			
			gen type = "short-run"

			foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
				append using $temp/dl_ir_`y'_1_`x'.dta	
				}
				}
			replace region = "North" if region == ""
			
		foreach y in farming forest livestock fishery {
		foreach x in 05 10 15 20 {
				append using $temp/dl_ir_`y'_2_`x'.dta	
				}
				}		
			replace region = "South" if region == ""					
			
			replace type = "intermediate-run" if type == ""
		
		drop label
		rename idnum level
		rename estimate coef 
		rename stderr se 
		rename min95 ci_l
		rename max95 ci_h	
		rename idstr sector
		replace sector = "Cropping" if sector=="farming"
		replace sector = "Forestry" if sector=="forest"
		replace sector = "Livestock" if sector=="livestock"
		replace sector = "Fishery" if sector=="fishery"
		
		save $visual/bote_dl, replace			
		
	// delete dta data 
	cd $temp/
	fs *.dta
	foreach f in `r(files)'{
	   erase "`f'"
	}		
					
